#ifndef _MODULE_MOTION_H_
#define _MODULE_MOTION_H_

#ifdef __cplusplus
 extern "C" {
#endif
#include "includes.h"

#ifdef _MODULE_MOTION_GLOBALS
#define _MODULE_MOTION_EXT
#else
#define _MODULE_MOTION_EXT   extern
#endif

typedef __packed union
{
	__packed struct {
		uint16_t BldcRight:12;
		uint16_t BldcMid:12;
		uint16_t BldcLeft:12;
		uint16_t BldcSieve:12;
		uint16_t Screen:12;
	}PWM;
	__packed struct {
	  uint8_t CylinderCube;
		uint8_t CylinderClaw;
		uint8_t CylinderSlide;
		uint8_t CylinderFork;
		uint8_t CylinderDownFork;
			uint8_t VIDEO_2;
	}Delay;
	__packed struct {
	    int32_t Position;
		int16_t Speed;
		int16_t Timeout;
	}MCWL;
	__packed struct {
	    int32_t LSpeed;
		int32_t RSpeed;
	}Pedrail;
}CanMsg_1_0_TypeDef;

#define CanMsg(p) (*((CanMsg_1_0_TypeDef *)p))

#define Cylinder_Cube_ControlID	0x121
#define Cylinder_Claw_ControlID	0x122
#define Cylinder_Slide_ControlID	0x123
#define Cylinder_Fork_ControlID	0x124
#define Cylinder_Down_Fork_ControlID 0x125
#define VIDEO_2_ControlID	0x126
#define ResetID			0x100
#define UpliftFrameID		0x141
#define UpliftFrame_2nd_ID	0x142	
#define Down_Slow_ID 0x143
#define MCWL_ResetCmd		0x097

typedef struct
{
	int32_t Position;
	int16_t Speed;
	int16_t Timeout;
}MCWL_CanMsgTypeDef;

_MODULE_MOTION_EXT uint8_t CylinderCubeFlag;
_MODULE_MOTION_EXT uint8_t CylinderClawFlag;
_MODULE_MOTION_EXT uint8_t CylinderSlideFlag;
_MODULE_MOTION_EXT uint8_t CylinderForkFlag;
_MODULE_MOTION_EXT uint8_t CylinderDownForkFlag;
_MODULE_MOTION_EXT uint8_t VIDEO_2_FLAG;
_MODULE_MOTION_EXT uint8_t Screen_Act_Flag;

_MODULE_MOTION_EXT int16_t BldcRight,BldcMid,BldcLeft,BldcSieve,Screen;
_MODULE_MOTION_EXT MCWL_CanMsgTypeDef UpliftFrameMsg,UpliftFrameMsg_2nd;
_MODULE_MOTION_EXT int32_t PedrailLSpeed,PedrailRSpeed;
_MODULE_MOTION_EXT void Reset_MCWL(void);

_MODULE_MOTION_EXT void SpeedLight(void);
	
void Cylinder_CubeControl(int8_t CylinderCubeFlag);
void Cylinder_ClawControl(int8_t CylinderClawFlag);
void Cylinder_SlideControl(int8_t CylinderSlideFlag);
void Cylinder_ForkControl(int8_t CylinderForkFlag);
void Cylinder_Down_ForkControl(int8_t CylinderDownForkFlag);
void VIDEO_2_Control(int8_t VIDEO_2_Flag);
void Reset_all(void);
_MODULE_MOTION_EXT void UpliftFrame(int32_t Position,int16_t Speed,int16_t Timeout);
_MODULE_MOTION_EXT void UpliftFrame_2nd(int32_t Position,int16_t Speed,int16_t Timeout);
_MODULE_MOTION_EXT void Send_Down_Slow_Flag(void);
#ifdef __cplusplus
 }
#endif

#endif




